#include "fs-util.h"

#include <string>
#include <fstream>

#include "strutil.h"

namespace fsutil
{

bool isUpperThan(const fs::path &upper, const fs::path &lower) {
    const std::string absUpper = fs::absolute(upper).lexically_normal().generic_string();
    const std::string absLower = fs::absolute(lower).lexically_normal().generic_string();
    return absLower.length() > absUpper.length() && strutil::startWith(absLower, absUpper);
}

bool isSamePath(const fs::path &a, const fs::path &b) {
    const std::string absA = fs::absolute(a).lexically_normal().generic_string();
    const std::string absB = fs::absolute(b).lexically_normal().generic_string();
    return absA == absB;
}

std::string content(const fs::path &p) {
    std::string result;
    result.resize(fs::file_size(p));
    std::ifstream ifs(p.generic_string(), std::ios::binary);
    ifs.read(result.data(), result.size());
    return result;
}

bool haveSameContent(const fs::path &a, const fs::path &b) {
    return content(a) == content(b);
}

} // namespace fsutil
